package com.corey.utils;

import com.xw.wuliu.R;

import android.app.Activity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TitleActivity extends Activity implements OnClickListener{
	
	    protected TextView               mTitle;
	    protected Button                 mLeftBtn;
	    protected Button                 mRightBtn;
	    
	    protected void setupViews() {
	        mTitle = ( TextView ) findViewById( R.id.title );
	        mLeftBtn = ( Button ) findViewById( R.id.title_btn_left );
	        mRightBtn = ( Button ) findViewById( R.id.title_btn_right );
	        mLeftBtn.setOnClickListener( this );
	        mRightBtn.setOnClickListener( this );
	    }
	    
	    /**
	     * 左button被点击
	     */
	    protected void onLeftBtnClick() {
	    }

	    /**
	     * 右button被点击
	     */
	    protected void onRightBtnClick() {
	    }
	    
	    public void setTitleText( final String title ) {
	        if ( mTitle != null ) {
	            mTitle.setText( title );
	        }
	    }

	    /**
	     * 设置左右button的可见性
	     * 
	     * @param leftVisibility
	     * @param rightVisibility
	     */
	    public void setBtnVisibility( final int leftVisibility, final int rightVisibility ) {
	        if ( mLeftBtn != null ) {
	            mLeftBtn.setVisibility( leftVisibility );
	        }
	        if ( mRightBtn != null ) {
	            mRightBtn.setVisibility( rightVisibility );
	        }
	    }

	    public void setBtnText( final int leftText,final int rightText ) {
	    	setLeftBtnText(leftText);
	    	setRightBtnText(rightText);
	    }
	    
	    /**
	     * 设置左btn的文字
	     * 
	     * @param leftText
	     * @param rightText
	     */
	    public void setLeftBtnText( final int leftText ) {
	        if ( mLeftBtn != null ) {
	            mLeftBtn.setText( leftText );
	        }

	    }

	    /**
	     * 设置右btn的文字
	     * 
	     * @param leftText
	     * @param rightText
	     */
	    public void setRightBtnText(final int rightText ) {

	        if ( mRightBtn != null ) {
	            mRightBtn.setText( rightText );
	        }
	    }
	    
	    /**
	     * 设置标题文字
	     * 
	     * @param titleId
	     */
	    public void setTitleText( final int titleId ) {
	        if ( mTitle != null ) {
	            mTitle.setText( titleId );
	        }
	    }
	    
	    public void setFullScreen(boolean b){
	    	if( b ){
	    		requestWindowFeature(Window.FEATURE_NO_TITLE);
	    		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
	    				WindowManager.LayoutParams.FLAG_FULLSCREEN);
	    	}else{
	    	}
	    }
	    
		@Override
		public void onClick(View v) {
			 if ( v == mLeftBtn ) {
		            onLeftBtnClick();
		        }
		     else if ( v == mRightBtn ) {
		            onRightBtnClick();
		        }
		}
}
